package com.tanhua.mangement.controller;

import com.tanhua.mangement.service.CommentsService;
import com.tanhua.mangement.vo.CommentsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("manage/messages")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    @GetMapping("comments")
    public ResponseEntity<CommentsVo> getComments(
            @RequestParam(value = "pagesize", required = false,defaultValue = "10")String pagesize,
            @RequestParam(value = "page", required = false,defaultValue = "1")String page,
            @RequestParam(value = "sortProp")String sortProp,
            @RequestParam(value = "sortOrder")String sortOrder,
            @RequestParam(value = "messageID")String messageID){

        try {
            CommentsVo commentsVo = commentsService.getComments(pagesize,page,sortProp,sortOrder,messageID);
            if (commentsVo != null) {
                return ResponseEntity.ok(commentsVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
